package com.Lyy.Config;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan({"com.Lyy.Service"})
@MapperScan("com.Lyy.Dao")
public class SpringConfig {
    @Bean
    public DruidDataSource getDataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql:///?demo");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");
        return dataSource;
    };
    @Bean
    public SqlSessionFactoryBean getSqlSessionFactoryBean(DruidDataSource dataSource){
        SqlSessionFactoryBean SSFB = new SqlSessionFactoryBean();
        SSFB.setDataSource(dataSource);
        return SSFB;
    }
}
